<script lang="ts">
import { defineComponent, ref } from "vue";
import { useStore } from "@/store/store.js";
import router from "@router/index.js"  // 引入router
//import http from "@/api/config";
import axios from 'axios'

export default defineComponent({
  setup() {
    const store = useStore();
    const getUserInfo = () => {
      axios.post("/api/login").then((res) => {
        console.log(res); //这里返回的就是我们在mock中自定义的数据
        var user=res.data.data;
        if(user.pwd==123){
          //记录用户信息
          store.id=user.id;
          store.name=user.userName;
          store.token=user.token;

          router.addRouter
          //跳转
          router.push({
              path:'/'
          });
        }
      });
    };

    return {
      getUserInfo,
    };
  },
});
</script>
<template>
  这里是login
  <br />
  <button @click="getUserInfo">登录</button>
</template>